<?php

$servername = "localhost";
$username = "root";
$password = "root";

try {
    $conn = new PDO("mysql:host=$servername;dbname=hoho;", $username, $password);
    echo "连接成功<br/>";
} catch (PDOException $e) {
    echo $e->getMessage();
}

//$conn->exec("set names utf8;");

$sql="select * from dish;";
$sqle=$conn->prepare($sql);
$w=$sqle->execute();
$a=$sqle->fetchAll();
$size=sizeof($a);
?>

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>
<body>
<?php

for ($i = 0; $i < $size; $i = $i + 1) {
  $item = $a[$i];
  ?>

  <div>
    菜品：
    <?php echo $item['name']; ?>
    价格：
    <?php echo $item['price']; ?>
    图片：
    <img style="width:100px" src="<?php echo $item['icon']; ?>" />
  </div>

<?php } ?>

</body>
</html>